<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="member_id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="memberId">
              <a-input-number v-model="model.memberId" placeholder="请输入member_id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderSn">
              <a-input v-model="model.orderSn" placeholder="请输入订单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="使用的优惠券" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponId">
              <a-input-number v-model="model.couponId" placeholder="请输入使用的优惠券" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="memberUsername">
              <a-input v-model="model.memberUsername" placeholder="请输入用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单总额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalAmount">
              <a-input-number v-model="model.totalAmount" placeholder="请输入订单总额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="应付总额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payAmount">
              <a-input-number v-model="model.payAmount" placeholder="请输入应付总额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运费金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="freightAmount">
              <a-input-number v-model="model.freightAmount" placeholder="请输入运费金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="促销优化金额（促销价、满减、阶梯价）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="promotionAmount">
              <a-input-number v-model="model.promotionAmount" placeholder="请输入促销优化金额（促销价、满减、阶梯价）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="积分抵扣金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="integrationAmount">
              <a-input-number v-model="model.integrationAmount" placeholder="请输入积分抵扣金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优惠券抵扣金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponAmount">
              <a-input-number v-model="model.couponAmount" placeholder="请输入优惠券抵扣金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="后台调整订单使用的折扣金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discountAmount">
              <a-input-number v-model="model.discountAmount" placeholder="请输入后台调整订单使用的折扣金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付方式【1->支付宝；2->微信；3->银联； 4->货到付款；】" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payType">
              <a-input-number v-model="model.payType" placeholder="请输入支付方式【1->支付宝；2->微信；3->银联； 4->货到付款；】" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单来源[0->PC订单；1->app订单]" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sourceType">
              <a-input-number v-model="model.sourceType" placeholder="请输入订单来源[0->PC订单；1->app订单]" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态【0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单】" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入订单状态【0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；5->无效订单】" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物流公司(配送方式)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryCompany">
              <a-input v-model="model.deliveryCompany" placeholder="请输入物流公司(配送方式)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物流单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliverySn">
              <a-input v-model="model.deliverySn" placeholder="请输入物流单号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="自动确认时间（天）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="autoConfirmDay">
              <a-input-number v-model="model.autoConfirmDay" placeholder="请输入自动确认时间（天）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="可以获得的积分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="integration">
              <a-input-number v-model="model.integration" placeholder="请输入可以获得的积分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="可以获得的成长值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="growth">
              <a-input-number v-model="model.growth" placeholder="请输入可以获得的成长值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发票类型[0->不开发票；1->电子发票；2->纸质发票]" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billType">
              <a-input-number v-model="model.billType" placeholder="请输入发票类型[0->不开发票；1->电子发票；2->纸质发票]" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发票抬头" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billHeader">
              <a-input v-model="model.billHeader" placeholder="请输入发票抬头"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发票内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billContent">
              <a-input v-model="model.billContent" placeholder="请输入发票内容"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收票人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billReceiverPhone">
              <a-input v-model="model.billReceiverPhone" placeholder="请输入收票人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收票人邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billReceiverEmail">
              <a-input v-model="model.billReceiverEmail" placeholder="请输入收票人邮箱"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货人姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverName">
              <a-input v-model="model.receiverName" placeholder="请输入收货人姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverPhone">
              <a-input v-model="model.receiverPhone" placeholder="请输入收货人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收货人邮编" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverPostCode">
              <a-input v-model="model.receiverPostCode" placeholder="请输入收货人邮编"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="省份/直辖市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverProvince">
              <a-input v-model="model.receiverProvince" placeholder="请输入省份/直辖市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverCity">
              <a-input v-model="model.receiverCity" placeholder="请输入城市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverRegion">
              <a-input v-model="model.receiverRegion" placeholder="请输入区"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="详细地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiverDetailAddress">
              <a-input v-model="model.receiverDetailAddress" placeholder="请输入详细地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="note">
              <a-input v-model="model.note" placeholder="请输入订单备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确认收货状态[0->未确认；1->已确认]" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmStatus">
              <a-input-number v-model="model.confirmStatus" placeholder="请输入确认收货状态[0->未确认；1->已确认]" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除状态【0->未删除；1->已删除】" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deleteStatus">
              <a-input-number v-model="model.deleteStatus" placeholder="请输入删除状态【0->未删除；1->已删除】" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下单时使用的积分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useIntegration">
              <a-input-number v-model="model.useIntegration" placeholder="请输入下单时使用的积分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentTime">
              <j-date placeholder="请选择支付时间" v-model="model.paymentTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="发货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deliveryTime">
              <j-date placeholder="请选择发货时间" v-model="model.deliveryTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="确认收货时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiveTime">
              <j-date placeholder="请选择确认收货时间" v-model="model.receiveTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="评价时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="commentTime">
              <j-date placeholder="请选择评价时间" v-model="model.commentTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="修改时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="modifyTime">
              <j-date placeholder="请选择修改时间" v-model="model.modifyTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'OmsOrderForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/order/omsOrder/add",
          edit: "/order/omsOrder/edit",
          queryById: "/order/omsOrder/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>